package com.project.service.impl;

import com.project.bean.DrugBean;
import com.project.bean.OutDrugBean;
import com.project.dao.IDrugDao;
import com.project.service.IOutService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author RJ
 * @date 2022/9/15 19:39
 */
@Service
public class OutServiceImpl implements IOutService {

    @Resource
    private IDrugDao drugDao;

    @Override
    public void buy(Integer drugId, Map<Integer, OutDrugBean> map) {
        if (map.containsKey(drugId)) {
            OutDrugBean outDrugBean = map.get(drugId);
            outDrugBean.setNum(outDrugBean.getNum() + 1);
        } else {
            DrugBean drugBean = drugDao.selectById(drugId);
            OutDrugBean outDrugBean = new OutDrugBean();
            outDrugBean.setTheDrug(drugBean);
            outDrugBean.setNum(1);
            map.put(drugId, outDrugBean);
        }
    }

    @Override
    public void remove(Integer drugId, Map<Integer, OutDrugBean> map) {
        map.remove(drugId);
    }

    @Override
    public void updateNum(Integer drugId, Map<Integer, OutDrugBean> map, int number) {
        OutDrugBean outDrugBean = map.get(drugId);
        outDrugBean.setNum(number);
    }
}
